package com.block.datapush.service.extdata;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.block.datapush.model.ProtocolInfoEntity;
import com.block.datapush.service.IPushExtDataService;
import com.block.db.entity.MemberSourceInfo;
import com.block.db.entity.MerchantBaseInfo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DefaultPushExtDataServie implements IPushExtDataService {

    @Override
    public List<ProtocolInfoEntity> getProtocolUrl(MerchantBaseInfo merchantBaseInfo, MemberSourceInfo memberSourceInfo, JSONObject extObject) {

        List<ProtocolInfoEntity> protocolList = new ArrayList<>();
        try {
            if (StrUtil.isNotEmpty(merchantBaseInfo.getApiProtocolUrl())){
                String protocolUrl = StrUtil.format(merchantBaseInfo.getApiProtocolUrl(), merchantBaseInfo.getId(), memberSourceInfo.getUid());

                ProtocolInfoEntity infoEntity = new ProtocolInfoEntity();
                infoEntity.setProtocolUrl(protocolUrl);
                infoEntity.setProtocolName("授权协议");

                protocolList.add(infoEntity);
            }
        }catch (Exception exception){
            exception.printStackTrace();
        }

        return protocolList;
    }
}
